/**
 * @param {string} num1
 * @param {string} num2
 * @return {string}
 */
var multiply = function (num1, num2) {
  const len1 = num1.length
  const len2 = num2.length
  const pos = new Array(len1 + len2).fill(0)
  for (let i = len1 - 1; i >= 0; i--) {
    const n1 = +num1[i]
    for (let j = len2 - 1; j >= 0; j--) {
      const n2 = +num2[j]
      const multi = n1 * n2
      const sum = pos[i + j + 1] + multi
      pos[i + j + 1] = sum % 10
      pos[i + j] += sum / 10 | 0
    }
  }
  console.log(pos);
  while (pos[0] == 0) {
    pos.shift()
  }
  console.log(pos.length ? pos.join("") : "0");
  return pos.length ? pos.join("") : "0"
};

multiply("500", "500")

// arr = Array.fill(num1.length + num2.length)
// for (let i = num1.length - 1; i >= 0; i--){
//   const n1 = +num1[i]
//   for (let j = num2.length - 1; j >= 0; j--) {
//     const n2 = +num2[j]
//     const sum = n1 * n2
//     arr[i + j + 1] = sum % 10
//     arr[i + j] = sum / 10 | 0
//   }
//   while(arr[0] === 0) {
//     arr.shift()
//   }
//   return arr.length ? arr.join("") : 0
// }